package extreme.fizzbuzz;

import static extreme.fizzbuzz.CommonString.*;

public class FizzBuzzWhizzConvertor {

    public static String convert(int number) {
        String stringNumber = String.valueOf(number);
        if (number < 1) {
            throw new IllegalArgumentException();
        }
        if (stringNumber.contains(FIVE) && stringNumber.contains(SEVEN) && stringNumber.contains(THREE)) {
            return stringNumber;
        }
        if (stringNumber.contains(THREE) && stringNumber.contains(SEVEN)) {
            return BUZZ;
        }
        if (stringNumber.contains(FIVE) && stringNumber.contains(THREE)) {
            return WHIZZ;
        }
        if (stringNumber.contains(FIVE) && stringNumber.contains(SEVEN)) {
            return FIZZ;
        }
        if (stringNumber.contains(SEVEN)) {
            return WHIZZ;
        }
        if (stringNumber.contains(FIVE)) {
            return BUZZ_WHIZZ;
        }
        if (stringNumber.contains(THREE)) {
            return FIZZ;
        }
        if (isAliquot(number, 105)) {
            return FIZZ_BUZZ_WHIZZ;
        }
        if (isAliquot(number, 35)) {
            return BUZZ_WHIZZ;
        }
        if (isAliquot(number, 21)) {
            return FIZZ_WHIZZ;
        }
        if (isAliquot(number, 15)) {
            return FIZZ_BUZZ;
        }
        if (isAliquot(number, 3)) {
            return FIZZ;
        }
        if (isAliquot(number, 5)) {
            return BUZZ;
        }
        if (isAliquot(number, 7)) {
            return WHIZZ;
        }
        return stringNumber;
    }

    private static boolean isAliquot(int number, int i) {
        return number % i == 0;
    }
}